package we3d.material 
{
	import flash.display.BitmapData;
	import flash.filters.ColorMatrixFilter;
	import we3d.scene.LightGlobals;
	
	public class BitmapLightAttributes extends BitmapAttributes
	{
		public function BitmapLightAttributes (bitmap:BitmapData=null, luminosity:Number=0, diffuse:Number=1, lightGlobals:LightGlobals=null)  {
			super(bitmap);
			this.luminosity = luminosity;
			this.diffuse = diffuse;
			this.lightGlobals = lightGlobals;
		}
		
		public var cmf:ColorMatrixFilter;
		public var cmfMatrix:Array;
		private var initialized:Boolean=false;
		
		public override function init ():void {
			initialized = true;
			
			if(!cmfMatrix) {
				cmfMatrix = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; 
			}else{
				for(var i:int=1; i < cmfMatrix.length; i++) cmfMatrix[i] = 0;
				cmfMatrix[0] = 1;
				cmfMatrix[6] = 1;
				cmfMatrix[12] = 1;
				cmfMatrix[18] = 1;
			}
			
			if(!cmf) cmf = new ColorMatrixFilter(cmfMatrix);
			else cmf.matrix = cmfMatrix;
		}
		
		/**
		* Set the bitmap of the texture
		* @param	b the bitmapData
		* @return
		*/
		public override function set texture (b:BitmapData) :void {
			if(b is BitmapData) {
				if(!initialized) init();
				_texture = b;
				_w = b.width;
				_h = b.height;
			}else{
				_texture = null;
				_w = 0;
				_h = 0;
			}
		}
		
	}
}